package com.xncoding.netty.server.tcp;

import com.xncoding.netty.handler.tcp.StringTcpServerHandler;
import com.xncoding.netty.server.NettyServiceTemplate;
import io.netty.channel.ChannelHandler;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

public class StringTcpServer extends NettyServiceTemplate {
	private int port = 8088;
	private String name = "String Server";

	// SpringBeanService springBeanService;

	public StringTcpServer() {
	}
	public StringTcpServer(int port) {
		this.port = port;
	}

	@Override
	protected ChannelHandler[] createHandlers() {
		return new ChannelHandler[] { 
				new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()), //分隔符解码器,定义了以("\n")为结尾分割的 解码器
				new StringDecoder(), //String解码与编码器,将byte类型解析
				new StringEncoder(),//String编码，序列化
				new StringTcpServerHandler()
		};
	}

	@Override
	public int getPort() {
		return port;
	}

	@Override
	public String getName() {
		return name;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public void setName(String name) {
		this.name = name;
	}

}
